﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Csla.Xaml;
using HeThongThongTin.Library;
using System.Windows.Data;
using BusinessConfiguration;

namespace HeThongThongTin.UI.SL.HeThong.HT_QuanLyVaiTroNguoiDung
{
    public class HT_NguoiDung_VaiTro_ListViewModel : ViewModel<HT_NguoiDung_VaiTroList>
    {
        public event EventHandler LoadCompleted;
        

        public HT_NguoiDung_VaiTro_ListViewModel(int KhoaNguoiDung)
        {
            BeginRefresh("GetHT_NguoiDung_VaiTroList", KhoaNguoiDung);

        }

        public void GetHT_NguoiDung_VaiTro_ListViewModel(string mode)
        {
            BeginRefresh("GetHT_NguoiDung_VaiTroList", mode);
        }

        

        protected override void OnRefreshed()
        {
            base.OnRefreshed();
            if (Model != null)
            {
                if (LoadCompleted != null)
                {
                    LoadCompleted(this, new EventArgs());
                }
            }
        }

        public static readonly DependencyProperty SelectedItemProperty =
          DependencyProperty.Register("SelectedItem", typeof(HT_NguoiDung_VaiTroInfo), typeof(HT_NguoiDung_VaiTro_ListViewModel), null);
        public HT_NguoiDung_VaiTroInfo SelectedItem
        {
            get { return (HT_NguoiDung_VaiTroInfo)GetValue(SelectedItemProperty); }
            set { SetValue(SelectedItemProperty, value); }
        }

        public void DeleteHT_NguoiDung_VaiTro(object sender, ExecuteEventArgs e)
        {
            if (e.MethodParameter != null)
            {
                //cast parameter
                string parameter = e.MethodParameter.ToString();
                this.IsBusy = true;
                HeThongThongTin.Library.HT_NguoiDung_VaiTro.DeleteHT_NguoiDung_VaiTro(int.Parse(parameter), (o, ex) =>
                {
                    BeginRefresh("GetHT_NguoiDung_VaiTroList", BusinessConfiguration.Configuration.GridViewFetchMode);
                });
                this.IsBusy = false;
            }
        }
    }
}

 
			
        
 
				
        	